import { activeAnalysis } from '@/services/api/api-cues-active';
import { searchTreeOrganization } from '@/services/api/api-cues-submit';
import { PageContainer } from '@ant-design/pro-components';
import { ActionType } from '@ant-design/pro-table';
import RcResizeObserver from 'rc-resize-observer';
import React, { useEffect, useRef, useState } from 'react';
import { useAccess } from 'umi';
import AddActive from './components/AddActive';
import TableActive from './components/TableActive';
import './index.less';
const Active: React.FC = () => {
  const access = useAccess();

  const [width, setWidth] = useState(500);

  const actionRef = useRef<ActionType>();

  const [articleOrganizations, setArticleOrganizationState] = useState<any[]>([]);

  const [showList, setShowListState] = useState(false);
  const [selectTime, setSelectTimeState] = useState();

  /**
   * 加载 单位 列表
   * @param key
   */
  const treeOrganizationData = async () => {
    try {
      const response = await searchTreeOrganization();
      if (response.code === 0) {
        setArticleOrganizationState(response.data);
      }
    } catch (error) {}
  };

  /**
   * 搜索参数
   */
  const [queryParam, setQueryParamState] = useState({});
  const [loading, setLoadingState] = useState(true);
  const [responsive, setResponsive] = useState(false);
  const [totalData, setTotalDataState] = useState<CuesActiveData.Analysis>();
  useEffect(() => {
    treeOrganizationData();
    analysisData();
  }, []);
  /**
   * 加载 单位 列表
   * @param key
   */
  const analysisData = async () => {
    try {
      const response = await activeAnalysis();
      if (response.code === 0) {
        console.log(response.data);
        setLoadingState(false);
        setTotalDataState(response.data);
      }
    } catch (error) {}
  };

  return (
    <RcResizeObserver
      key="resize-observer"
      onResize={(size) => {
        setWidth(size.width);
      }}
    >
      <PageContainer
        header={{
          title: (
            <span
              style={{
                marginInlineEnd: '12px',
                color: 'rgba(0, 0, 0, 0.88)',
                fontWeight: 600,
                fontSize: 20,
                height: 48,
                paddingRight: 35,
              }}
              title="主动报送"
            >
              主动报送
            </span>
          ),
          breadcrumb: {
            items: [],
          },
          style: {
            paddingBlockEnd: 0,
          },
          extra: [
            access.主动报送x报送线索x页面 && (
              <AddActive
                key="add_active"
                onRefurbish={() => {
                  actionRef?.current?.reset();
                }}
              />
            ),
          ],
        }}
      >
        <TableActive actionRef={actionRef} createdTimes={selectTime} />
      </PageContainer>
    </RcResizeObserver>
  );
};
export default Active;
